<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c"
           uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://www.rapid-framework.org.cn/rapid" prefix="rapid" %>
<rapid:override name="head">
    <title>试题管理</title>
    <style>
        .btn-pink {
            background-color: #FFDAB9;
        }
        .line2{
            overflow : hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
        }

    </style>
</rapid:override>
<rapid:override name="content">
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    %>
    <div>
        <button type="button" onclick="insert()" class="layui-btn layui-btn-lg" style="margin-top:15px;">添加新题目</button>
    </div>
    <script>
        function insert() {
            layer.open({
                type: 2
                ,title: false //不显示标题栏
                ,closeBtn: false
                ,area: ['700px', '500px']
                ,shade: 0.8
                ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
                ,btn: ['取消']
                ,btnAlign: 'c'
                ,moveType: 1 //拖拽模式，0或者1
                ,content: '/admin/online/subjectAdd'
                ,success: function(layero){
                    // var btn = layero.find('.layui-layer-btn');
                    // btn.find('.layui-layer-btn0').attr({
                    //     href: 'http://www.layui.com/'
                    //     ,target: '_blank'
                    // });
                    layer.close({id:'LAY_layuipro'})
                }
            });
        }
    </script>
    <table class="layui-table" style="margin-top:15px; background-color: rgba(255,218,185,0.5);
        color: #000;">
        <colgroup>
            <col width="100">
            <col width="120">
            <col width="50">
            <col width="50">
            <col width="200">
            <col width="120">
        </colgroup>
        <thead>
        <tr>
            <th>题目</th>
            <th>类型</th>
            <th>答案</th>
            <th>分值</th>
            <th>创建时间</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${paging.dataList}" var="question">
            <tr>
                <td class="line2">${question.title}</td>
                <td>
                    <c:choose>
                        <c:when test="${question.type==1}">
                            单选
                        </c:when>
                        <c:when test="${question.type==2}">
                            多选
                        </c:when>
                        <c:when test="${question.type==3}">
                            填空
                        </c:when>
                        <c:when test="${question.type==4}">
                            判断
                        </c:when>
                        <c:when test="${question.type==5}">
                            问答
                        </c:when>
                    </c:choose>
                </td>
                <td class="line2">${question.answer}</td>
                <td>${question.score}</td>
                <td>${question.formateTime(question.createDate)}</td>


                <td>
                  <button class="layui-btn btn-pink" onclick="deletetQuestion(${question.id})">删除题目</button>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <div style="text-align:center; margin-top:10px; margin-left:-100px;" >
        <c:if test="${paging.totalPage >=0}">
            <p style=" color: black; font-size:16px; margin-bottom:10px;">当前第 ${paging.currentPage } 页/共  ${paging.totalPage} 页</p>
            <c:choose>
                <c:when test="${paging.totalPage==0}">
                    <button class="layui-btn layui-btn-disabled" onclick="goPage(1)">首页</button>
                    <button class="layui-btn layui-btn-disabled" onclick="goPage(${paging.currentPage-1})">上一页</button>
                    <button class="layui-btn layui-btn-disabled" onclick="goPage(${paging.currentPage+1})">下一页</button>
                    <button class="layui-btn layui-btn-disabled" onclick="goPage(${paging.totalPage})">末页</button>
                </c:when>
                <c:when test="${paging.currentPage==1 && paging.totalPage==1}">
                    <button class="layui-btn" onclick="goPage(1)">首页</button>
                    <button class="layui-btn layui-btn-disabled" onclick="goPage(${paging.currentPage-1})">上一页</button>
                    <button class="layui-btn layui-btn-disabled" onclick="goPage(${paging.currentPage+1})">下一页</button>
                    <button class="layui-btn" onclick="goPage(${paging.totalPage})">末页</button>
                </c:when>
                <c:when test="${paging.currentPage==1 && paging.totalPage>1}">
                    <button class="layui-btn" onclick="goPage(1)">首页</button>
                    <button class="layui-btn layui-btn-disabled" onclick="goPage(${paging.currentPage-1})">上一页</button>
                    <button class="layui-btn" onclick="goPage(${paging.currentPage+1})">下一页</button>
                    <button class="layui-btn" onclick="goPage(${paging.totalPage})">末页</button>
                </c:when>
                <c:when test="${paging.currentPage>1 && paging.currentPage<paging.totalPage}">
                    <button class="layui-btn" onclick="goPage(1)">首页</button>
                    <button class="layui-btn" onclick="goPage(${paging.currentPage-1})">上一页</button>
                    <button class="layui-btn" onclick="goPage(${paging.currentPage+1})">下一页</button>
                    <button class="layui-btn" onclick="goPage(${paging.totalPage})">末页</button>
                </c:when>
                <c:when test="${paging.currentPage>1 && paging.currentPage==paging.totalPage}">
                    <button class="layui-btn" onclick="goPage(1)">首页</button>
                    <button class="layui-btn" onclick="goPage(${paging.currentPage-1})">上一页</button>
                    <button class="layui-btn layui-btn-disabled" onclick="goPage(${paging.currentPage+1})">下一页</button>
                    <button class="layui-btn" onclick="goPage(${paging.totalPage})">末页</button>
                </c:when>
            </c:choose>
        </c:if>
    </div>
    <script>
        function goPage(page){
            window.location.href="<%=basePath%>admin/online/subject?page="+page;
        }
        function examDetail(classId) {
            window.location.href="<%=basePath%>admin/examDetail?courseid="+classId;
        }
        function insertExam(classId) {
            window.location.href="<%=basePath%>admin/insertExam?courseid="+classId;
        }
        function deletetQuestion() {

        }

        function delete_fun(classId) {
            var r=confirm("确认删除吗？")
            if (r==true)
            {
                window.location.href="<%=basePath%>teacher/deleteCourse?courseid="+classId;
            }
            else
            {
                return;
            }
        }
        function detail_fun(classId) {
            window.location.href="<%=basePath%>teacher/detailCourse?courseid="+classId+"&page="+1;
        }
    </script>
</rapid:override>
<%@ include file="../base.jsp" %>
